package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import com.mysql.jdbc.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class TestController {
    @Autowired
    private UserService userService;

    @GetMapping("/login")
    public User login(String username, String pwd, Integer age) {
   //    if (StringUtils.isBlack(username)) return "用户名不能为空";
//        if (StringUtils.isBlack(pwd)) return "密码不能为空";
        User user = userService.login(username, pwd);
        return user;
    }

    @GetMapping("/add")
    public String add(String username, String pwd, Integer age) {

        if (age != null && age <= 0) return "年龄输入错误";
        Boolean res = userService.add(username, pwd, age);
        if (res == true) return "添加成功";
        return "添加失败";
    }
}

